package com.wuyou.designPatterns.factory.abstractfactory.tablefactory;

import com.wuyou.designPatterns.factory.abstractfactory.factory.Item;
import com.wuyou.designPatterns.factory.abstractfactory.factory.Tray;

import java.util.Iterator;

public class TableTray extends Tray{
    public TableTray(String caption) {
        super(caption);
    }

    @Override
    public String makeHTML() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("<td>\n");
        buffer.append("<table width=\"100%\" border=\"1\">\n<tr>");
        buffer.append("<td bgcolor=\"#CCC\" align=\"center\" colspan=\"").append(tray.size()).append("\">").append("<b>").append(caption).append("</b></td>");
//        buffer.append("</td>\n").append("<tr>\n");
        buffer.append("</tr>\n");
        buffer.append("<tr>\n");
        Iterator<Item> iterator = tray.iterator();
        while (iterator.hasNext()){
            buffer.append(iterator.next().makeHTML());
        }
        buffer.append("</tr></table>").append("</td>");
        return buffer.toString();
    }
}
